/*  
 * 项目名: YYS 
 * 文件名: MediaPlayActivity.java  
 * 版权声明:
 *      本系统的所有内容，包括源码、页面设计，文字、图像以及其他任何信息，
 *      如未经特殊说明，其版权均属大华技术股份有限公司所有。
 *      Copyright (c) 2015 大华技术股份有限公司
 *      版权所有
 */
package com.shiwaixiangcun.customer.module.intelligent


import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.Log
import android.view.View
import com.shiwaixiangcun.customer.R
import com.shiwaixiangcun.customer.base.BaseActivity
import kotlinx.android.synthetic.main.activity_media_video.*
import kotlinx.android.synthetic.main.top_bar_white.*

/**
 * 描述：视频播放Activity 作者： lc
 *
 * @author Administrator
 */
class MediaPlayActivity : BaseActivity(), MediaPlayFragment.BackHandlerInterface {


    private var mMediaPlayFragment: MediaPlayFragment? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_media_video)


        val uuid = intent.getStringExtra("UUID")
        tv_page_name.text = "视频直播"
        //嵌入使用的帧
        val mediaPlayFragment: MediaPlayFragment //引用的布局帧
        val b = Bundle()

        mediaPlayFragment = MediaPlayOnlineFragment()
        b.putString("RESID", uuid)
        mediaPlayFragment.setArguments(b)
        changeFragment(mediaPlayFragment, false)

        back_left.setOnClickListener { finish() }

    }


    fun changeFragment(targetFragment: Fragment, isAddToStack: Boolean) {
        if (isAddToStack) {
            supportFragmentManager.beginTransaction().replace(R.id.frame_content, targetFragment).addToBackStack(null).commitAllowingStateLoss()
        } else {
            supportFragmentManager.beginTransaction().replace(R.id.frame_content, targetFragment).commitAllowingStateLoss()
        }

    }

    override fun onBackPressed() {
        if (mMediaPlayFragment == null || !mMediaPlayFragment!!.onBackPressed()) {
            Log.d(tag, "onBackPressed")
            super.onBackPressed()
        }
    }

    override fun setSelectedFragment(backHandledFragment: MediaPlayFragment) {
        this.mMediaPlayFragment = backHandledFragment
    }

    /**
     * 横竖屏切换需要,隐藏标题栏
     *
     * @param isShow
     */

    fun toggleTitle(isShow: Boolean) {
        llayout_toolbar!!.visibility = if (isShow) View.VISIBLE else View.GONE
    }

    companion object {

        private val tag = "MediaPlayActivity"
    }


}